package com.wangyadong.hobby.front.model.event;


import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

//@Configuration
public class MyListEventNotifierByAnnotation {

    @EventListener(condition = "#event.haveBaby==true")
    @Async
    public void processBlackListEvent(MyFirstEvent event) {
        // 监听event
        System.out.println(Thread.currentThread().getName() + " EventListener event.getBaby()-->" + event.getBaby());
    }

    /**
     * 不能发布事件
     * @param event
     */
    @EventListener
    @Async
    public void processBlackListEvent1(MyFirstEvent event) {
        // 监听event
        System.out.println(Thread.currentThread().getName() + " processBlackListEvent1 event.getBaby()-->" + event.getBaby());
    }


    @EventListener({ContextStartedEvent.class, ContextRefreshedEvent.class})
    public void processBlackListEvent() {
        // 监听event
        System.out.println("监听event-->");
    }

//    @EventListener(condition = "#event.baby==111")
//    public void processBlackListEventType(MyFirstEvent event) {
//        // 监听event
//        System.out.println("EventListener event.getBaby()==111 -->"+event.getBaby());
//    }


}
